package cz.schovjan.proj.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import cz.schovjan.proj.dao.ISongDao;
import cz.schovjan.proj.entity.SongEntity;

/**
 * Implementace ISongDao.
 * @author schovjan
 *
 */
@Repository
public class JpaSongDao implements ISongDao {

	private static final String FIND_ALL = "select s from SongEntity as s";
	
	@PersistenceContext
	private EntityManager em;
	
	
	@Override
	public void add(SongEntity se) {
		em.persist(se);
	}

	
	@SuppressWarnings("unchecked")
	@Override
	public List<SongEntity> findAll() {
		return em.createQuery(FIND_ALL).getResultList();
	}
	
	
	@Override
	public SongEntity find(Integer idS) {
		return em.find(SongEntity.class, idS);
	}
	
}
